package com.hindua.tab;

import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.hindua.tab.scr.CategoryScr;
import com.rtst.widget.tab.TabFragment;
import com.hindua.ailaaicuaai.R;

public class CategoryTab extends MyTab {
	private static final String TAG = "CategoryTab";
	
	public ViewGroup mLayout;
	private int mType;
	
	public CategoryTab() {
	}

	public CategoryTab(int type) {
		mType = type;
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		if(mLayout == null ) {
			mLayout = (ViewGroup) inflater.inflate(R.layout.tab_category_layout, container, false);
			createFirstScr();
		} else {
			((ViewGroup) mLayout.getParent()).removeView(mLayout);
		}
		return mLayout;
	}

	@Override
	public void createFirstScr() {
		FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
		TabFragment fragment = (TabFragment) getActivity().getSupportFragmentManager().findFragmentByTag(R.id.tab_category_container +  CategoryScr.class.getSimpleName());
		if(fragment != null) {
			ft.remove(fragment);
		}
		fragment = new CategoryScr(mType);
		fragment.setRootTabTag(getTag());
		ft.add(R.id.tab_category_container, fragment, getTag() + "/" + R.id.tab_category_container +  CategoryScr.class.getSimpleName());
		ft.commit();
	}
}

